package com.demo65;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

//2.在项目中导入MySQL的驱动包（依赖包），右键依赖，然后点击倒数第二个选项add as....点击ok即可
//3.编写main方法
//4.
public class TestConnection {
    //要让一个变量变成常量，需要像加一个find关键词，也就是不能够赋值。常量被改为大写写法
    private final static String URL = "jdbc:mysql://localhost:3306/usersDb";
    private final static String ROOT = "root";
    private final static String PASSWORD = "123456";

    public static void main(String[] args) throws SQLException {
        //1.连接MySQL数据库；如何连接? (url; localhost 3306 数据库的名称)用户名root 123456
         Connection connection = DriverManager.getConnection(URL, ROOT, PASSWORD);

        //2.编写SQL语句
        String sql = "insert into users(username,password) values(2,2);";

        //3.执行SQL语句
        PreparedStatement preparedStatement = connection.prepareStatement(sql);//预编译

        int i = preparedStatement.executeUpdate();
        if(i>1){System.out.println("注册成功");}

    }
}